﻿using System;
using System.Collections.Generic;
using Loki.Data;
using Luna.Model.Common;

namespace Luna.Data.Common
{
    internal class SearchProvider : LokiDataProvider, ISearchProvider
    {
        public GeolocalisationDataMapper GeolocMapper { get; set; }

        public SearchDataMapper TextMapper { get; set; }

        public IEnumerable<ISearchData> TextSearchGetAll()
        {
            return WrapperTransactional(T => TextMapper.GetAll(T));
        }

        public ISearchData TextSearchGet(Guid reference)
        {
            return WrapperTransactional(T => TextMapper.Get(T, reference));
        }

        public IEnumerable<ISearchData> TextSearch(string searchToken, int rows)
        {
            return WrapperTransactional(T => TextMapper.Search(T, searchToken, rows));
        }

        public void TextSearchSave(ISearchData data)
        {
            WrapperTransactional(T => TextMapper.Save(T, data));
        }

        public void TextSearchDelete(Guid reference)
        {
            WrapperTransactional(T => TextMapper.Delete(T, reference));
        }

        public IEnumerable<IGeolocalisationData> GeolocalisationGetAll()
        {
            return WrapperTransactional(T => GeolocMapper.GetAll(T));
        }

        public IGeolocalisationData GeolocalisationGet(Guid reference)
        {
            return WrapperTransactional(T => GeolocMapper.Get(T, reference));
        }

        public IEnumerable<IGeolocalisationData> GeolocalizationSearch(IGeoData localisation, float distance, int rows)
        {
            return WrapperTransactional(T => GeolocMapper.Search(T, localisation, distance, rows));
        }

        public void GeolocalisationSave(IGeolocalisationData data)
        {
            WrapperTransactional(T => GeolocMapper.Save(T, data));
        }

        public void GeolocalisationDelete(Guid reference)
        {
            WrapperTransactional(T => GeolocMapper.Delete(T, reference));
        }
    }
}